package com.cungmua.app.utils;

import android.content.Context;
import android.content.res.AssetManager;
import android.content.res.Resources;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * Created by kelvin.nguyen on 6/16/14.
 */
public class AppConfig {
    static String apiEndpoint = "http://example.com";
    static int apiVersion = 1;
    private static String defaultToken;
    static String yahooLoginEndpoint;
    static String googleLoginEndpoint;
    static String forgotPass;

    public static void loadConfig(Context context) {
        Resources resources = context.getResources();
        AssetManager assetManager = resources.getAssets();

        try {
            InputStream inputStream = assetManager.open("appconfig.properties");
            Properties properties = new Properties();
            properties.load(inputStream);
            apiVersion = Integer.parseInt(properties.getProperty("API_VERSION"));
            apiEndpoint = properties.getProperty("API_ENDPOINT");
            defaultToken = properties.getProperty("DEFAULT_TOKEN");
            yahooLoginEndpoint = properties.getProperty("YAHOO_LOGIN_URL");
            googleLoginEndpoint = properties.getProperty("GOOGLE_LOGIN_URL");
            forgotPass = properties.getProperty("FORGOT_PASSWORD");
        } catch (IOException e) {
            System.err.println("Failed to open property file");
            e.printStackTrace();
        }
    }

    public static String getDefaultToken() {
        return defaultToken;
    }

    public static String getApiEndpoint() {
        return apiEndpoint;
    }

    public static int getApiVersion() {
        return apiVersion;
    }

    public static String getYahooLoginEndpoint() {
        return yahooLoginEndpoint;
    }

    public static String getGoogleLoginEndpoint() {
        return googleLoginEndpoint;
    }

    public static String getforgotPass() { return forgotPass; }
}
